﻿using Security;
using System.Web.Mvc;

namespace HomeWeb.Controllers
{
    public class PasswordGeneratorController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult ShowPassword(string password, bool disableAlphabet, bool disableNumber, bool disableSymbol)
        {
            var r = new ShowPasswordResult(password, !disableAlphabet, !disableNumber, !disableSymbol);
            return View(r);
        }
    }

    public class ShowPasswordResult
    {
        public ShowPasswordResult(string password, bool enableAlphabet, bool enableNumber, bool enableSymbol)
        {
            var charset = (enableAlphabet ? PasswordCharset.Alphabet : PasswordCharset.None)
                | (enableNumber ? PasswordCharset.Number : PasswordCharset.None)
                | (enableSymbol ? PasswordCharset.Symbol : PasswordCharset.None);

            var g = new PasswordGenerator(password);

            MD5 = g.PasswordHash;
            Password = g.GeneratePassword(charset);
        }

        public string MD5 { get; private set; }
        public string Password { get; private set; }
    }
}
